package com.heima.account.service;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

@LocalTCC
public interface AccountTCCService {
   /*
   *  一阶段: try 预留
   *  @TwoPhaseBusinessAction 定义 try confirm cancel 方法名
   * */
    @TwoPhaseBusinessAction(name="deduct",commitMethod = "confirm",rollbackMethod = "cancel")
    void deduct(@BusinessActionContextParameter(paramName = "userId") Integer userId,
                @BusinessActionContextParameter(paramName ="money") Integer money);

    /*
    * 二阶段: confirm 提交
    * @param ctx 可以获得 @BusinessActionContextParameter参数和xid
    *
    * */
    Boolean confirm(BusinessActionContext ctx);

    /*
    *  二阶段: cancel 回滚
    * @param ctx 可以获得 @BusinessActionContextParameter 参数和xid
    * */
    Boolean cancel(BusinessActionContext ctx);
}
